<!--查看应聘者，米娜事，考核，录用-->
<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>物料使用排行</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="hearder-search">
          <div class="breadcrumb-container">
<!--            <el-input v-model="searchForm.name" placeholder="领用人" size="small"-->
<!--                      class="w-140 mr-10"></el-input>-->
            <el-date-picker
                v-model="addtime"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                size="small">
            </el-date-picker>
            <el-button type="primary" size="small" @click="searchFn('search')" class="ml-10"><i
                class="el-icon-search"></i>搜索
            </el-button>
            <el-button size="small" @click="searchFn('refresh')"><i class="el-icon-refresh"></i>重置刷新</el-button>
            <downexcel type="Material_consumption" :option="{start_time: searchForm.start_time, end_time: searchForm.end_time}"></downexcel>
          </div>
        </div>
        <el-table
            ref="multipleTable"
            :data="arryList"
            :border="tableoption.tableBorder"
            tooltip-effect="dark"
            :height="tableHeight"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              label="物料名称"
              align="center">
            <template slot-scope="scope">
              {{ scope.row.materiel ? scope.row.materiel.name : '未知' }}
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              prop="sum"
              label="使用数量">
          </el-table-column>
        </el-table>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              :page-size="page.pagesize"
              :current-page="page.pageindex"
              layout="total, prev, pager, next"
              :total="page.total"
              @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button type="primary" @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'

export default {
  props: ['visible'], // recruitId 招聘id
  components: {},
  data() {
    return {
      dialogVisible: false,
      tableoption: tableoption,
      arryList: [],
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      tableHeight: 0,
      searchForm: {
        p: 1,
        start_time: '', // 开始时间
        end_time: '', // 结束时间
      },
      addtime: []
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if(this.visible){
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51 + 50 + 60 + 51)
        })
        this.InitFn()
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化
    async InitFn() {
      this.searchForm.p = this.page.pageindex;
      let data = await this.$fetch(this.api.mater.useIt, this.searchForm);
      this.arryList = data.list.data
      this.page.total = data.list.total
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    searchFn(option) {
      if (option === 'refresh') {
        this.addtime = [];
        this.searchForm.start_time = '';
        this.searchForm.end_time = '';
        this.searchForm.name = '';
      }else{
        this.searchForm.start_time = this.addtime[0] || '';
        this.searchForm.end_time = this.addtime[1] || '';
      }
      this.page.pageindex = 1;
      this.InitFn()
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 0 10px 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}
</style>


